'use strict';
const db = uniCloud.database();
exports.main = async (event, context) => {
	try {
		const {
			orderid,
			newStatus
		} = event;
		if (!orderid || !newStatus) {
			return {
				code: -1,
				message: '缺少参数或参数不正确'
			};
		}

		// 更新订单状态为已完成
		const updateRes = await db.collection('orders').where({
			no: orderid
		}).update({
			status: newStatus
		});

		if (updateRes.updated === 1) {
			return {
				code: 0,
				message: '订单状态已更新为已完成'
			};
		} else {
			return {
				code: -1,
				message: '更新订单状态失败'
			};
		}
	} catch (error) {
		return {
			code: -1,
			message: '云函数执行出错',
			error
		};
	}
};




// exports.main = async (event, context) => {
//   const { username, password } = event;
//   if (username && password) {
//     const uniID = require('uni-id');
//     const res = await uniID.register({
//       username,
//       password,
//     });
//     return res;
//   } else {
//     return {
//       code: -1,
//       message: '缺少用户名和密码',
//     };
//   }
// };
